<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model as EloquentModel;

class Model extends EloquentModel
{
    /**
     * 基本的公用状态 0:false
     * 禁用状态
     */
    const FALSE_STATUS = 0;

    /**
     * 基本的公用状态 1:true
     * 启用状态
     */
    const TRUE_STATUS = 1;

    /**
     * 排序
     * @param $query
     * @return mixed
     */
    public function scopeSort($query)
    {
        return $query->orderByRaw('sort is null')->orderBy('sort', 'asc')->orderBy('created_at', 'desc');
    }

    /**
     * 是否显示
     * @param $query
     * @param $showStatus
     * @return mixed
     */
    public function scopeIsShow($query, $showStatus){
        return $query->where('is_show', $showStatus);
    }

    /**
     * 是否启用
     * @param $query
     * @return mixed
     */
    public function scopeEnable($query, $enableStatus = self::TRUE_STATUS)
    {
        return $query->where('is_enable', $enableStatus);
    }

}
